<template>
	<view class="pagesBox">
		<block v-for="(item,index) in goodsList" :key="index">
			<my-goods :goodsInfo="item"></my-goods>
		</block>
		<uni-load-more v-if="total > 0" :status="statusType"></uni-load-more>
		<view style="margin-top: 10rpx;" v-if="total == 0"><u-empty text="暂无推荐" mode="list"></u-empty></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsList:[],
				total:-1,
				statusType:'more',
				params:{
					limit:3,
					page:1,
					recommend:1
				}
			};
		},
		onLoad() {
			this.getGoods()
		},
		methods:{
			// 获取推荐信息
			async getGoods(){
				let res = await uni.$http('POST','goods/list',this.params);
				if(res.code == 1){
					this.params.page = res.data.current_page;
					this.total = res.data.total;
					if(this.params.page == 1){
						this.goodsList = res.data.data;
					}else{
						this.goodsList = this.goodsList.concat(res.data.data);
					}
					if(this.goodsList.length < this.total){
						this.statusType = 'more'
					}else{
						this.statusType = 'noMore'
					}
				}else if(res.msg.includes('登录')){
					this.total = 0;
					uni.removeStorageSync("token")
				}else{
					this.total = 0;
				}
			},
		},
		onReachBottom() {
			if(this.goodsList.length < this.total){
				this.statusType = 'loading';
				this.params.page++;
				this.getGoods()
			}else{
				this.statusType = 'noMore'
			}
		}
	}
</script>

<style scoped lang="scss">
.pagesBox{
	padding: 12rpx 24rpx;
}
</style>
<style>
	page{
		background-color: #151E2C;
	}
</style>